/*
 * > /*
>  * INSANE - Interactive Structural Analysis Environment
>  *
>  * Copyright (C) 2003-2004
>  * Universidade Federal de Minas Gerais
>  * Escola de Engenharia
>  * Departamento de Engenharia de Estruturas
>  *
>  * Author's email :     insane@dees.ufmg.br
>  * Author's Website :   http://www.dees.ufmg.br/insane
>  *
>  * This program is free software; you can redistribute it and/or
>  * modify it under the terms of the GNU General Public License
>  * as published by the Free Software Foundation; either version 2
>  * of the License, or any later version.
>  *
>  * This program is distributed in the hope that it will be useful,
>  * but WITHOUT ANY WARRANTY; without even the implied warranty of
>  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>  * GNU General Public License for more details.
>  *
>  * You should have received a copy of the GNU General Public License
>  * along with this program; if not, write to the Free Software
>  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-
> 1307, USA.
 *
 */

package br.ufmg.dees.insane.ui.rich.prep.view.command;

import java.util.ArrayList;

import javax.swing.JFrame;
import javax.swing.JOptionPane;

import br.ufmg.dees.insane.commons.command.Command;
import br.ufmg.dees.insane.model.geo.halfEdgeDataStructure.Edge;
import br.ufmg.dees.insane.model.geo.halfEdgeDataStructure.Vertex;
import br.ufmg.dees.insane.ui.rich.prep.controller.PrepControllerHE;
import br.ufmg.dees.insane.ui.rich.prep.view.DesktopPrep;
import br.ufmg.dees.insane.ui.rich.prep.view.InquiryView;
import br.ufmg.dees.insane.ui.rich.prep.view.InterfacePrep;

/**
 *
 * @author Ferreira, Reginaldo & Pitangueira, Roque
 * @since february, 2007
 */
public class InquiryCommand implements Command {
	
    private DesktopPrep desktop;
    private InterfacePrep intFrame;
    private PrepControllerHE controller;
    //private JTextArea results;
    
//  ****************************************************************************
	
    /** Inquiry Command */
    public InquiryCommand() {}
    
    /** This constructor receives a desktop and the current internal frame*/
    public InquiryCommand(JFrame dtk, InterfacePrep intF)
    {
        this.desktop = (DesktopPrep)dtk;
        this.intFrame = intF;
    } 
    
//  ****************************************************************************
	
    public void execute()
    {
    	String msg = "";
    	Vertex v1, v2;
    	Object obj;
        controller = (PrepControllerHE)this.intFrame.getView().getController();
        ArrayList selections = new ArrayList();
        selections = controller.getSelection();
    	
    	if (!selections.isEmpty())
    	{
    		msg = "\nInquiring < " + selections.size() + " > elements:";
    		desktop.getDesktopTextArea().addText(msg);
    		
    		for (int i=0; i<selections.size(); i++)
    		{
    			obj = (Object)selections.get(i);
    		
    			if (obj instanceof Vertex)
    			{
    				v1 = (Vertex)obj;
    				msg = "[" + (i+1) + "] node " + InquiryView.getCoordsStr(v1);	
    			}
    		
    			if (obj instanceof Edge)
    			{
    				Edge edge = (Edge)obj;
    				v1 = edge.getVStart();
    				v2 = edge.getVEnd();
    				msg = "[" + (i+1) + "] bar  [ vStart: " + InquiryView.getCoordsStr(v1) +
    			                 "   vEnd: " + InquiryView.getCoordsStr(v2) + " ]";
    			}
    	    	desktop.getDesktopTextArea().addText(msg);

    		}// for
            //this.results = desktop.getDesktopTextArea().getTextArea();
	    	//new TextAreaDialog(desktop, "Commands History", true, results);
    	}// if
    	else
    	{
    		msg = "There aren't elements selected.";
    		desktop.getDesktopTextArea().addText(msg);
			JOptionPane.showMessageDialog(desktop, msg,
					"Alert Message", JOptionPane.INFORMATION_MESSAGE);
    	}
    }// execute
    
//  ****************************************************************************
	
    /** Impossible to undo. */
    public void undo() {
    }
	
//  ****************************************************************************
	
    /** Impossible to redo. */
    public void redo() {
    }
  
//	****************************************************************************
    
    /** Sets the desktop and the current internal frame. */
    public void setParent(InterfacePrep currentIntFrame, DesktopPrep dsk)
	{
		this.desktop = (DesktopPrep)dsk;
		this.intFrame = currentIntFrame;
	}  
    
//	****************************************************************************   
}
